﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public abstract class EasySDKCallBackListener : MonoBehaviour
{
    public abstract void OnInit(bool isSuccess,string error);

    public abstract void OnLogin(bool isSuccess, string error);

    public abstract void OnLogout(bool isSuccess, string error);



    public abstract void OnPay(bool isSuccess, string orderId, string error);



    private bool isSuccess;
    private string error;
    private void OnSDKCallBack(string str)
    {
        Debug.Log("OnSDKCallBack :" + str);

        Deserializer deserializer = new Deserializer();
        Dictionary<string, string> data = deserializer.Deserialize<Dictionary<string,string>>(str);

        string functionName = data[EasySDKConstParameterName.ParameterName_FunctionName];

        switch (functionName)
        {
            case EasySDKConstFunctionName.FunctionName_OnInit:
                 isSuccess = bool.Parse(data[EasySDKConstParameterName.ParameterName_IsSuccess]);
                 error = data[EasySDKConstParameterName.ParameterName_Error];
                OnInit(isSuccess, error);
                break;
            case EasySDKConstFunctionName.FunctionName_OnLogin:
                 isSuccess = bool.Parse(data[EasySDKConstParameterName.ParameterName_IsSuccess]);
                 error = data[EasySDKConstParameterName.ParameterName_Error];
                OnLogin(isSuccess, error);
                break;
            case EasySDKConstFunctionName.FunctionName_OnLogout:
                isSuccess = bool.Parse(data[EasySDKConstParameterName.ParameterName_IsSuccess]);
                error = data[EasySDKConstParameterName.ParameterName_Error];
                OnLogout(isSuccess, error);
                break;
            case EasySDKConstFunctionName.FunctionName_OnPay:
                isSuccess = bool.Parse(data[EasySDKConstParameterName.ParameterName_IsSuccess]);
                error = data[EasySDKConstParameterName.ParameterName_Error];
                string goodId = data[EasySDKConstParameterName.ParameterName_GoodsID];
                OnPay(isSuccess,goodId, error);
                break;
        }
    }
}
